package net.zigin.nhi.could.waste.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.zigin.commons.util.ReflectUtil;
import net.zigin.nhi.could.waste.annotation.EpiResponseFilter;
import net.zigin.nhi.could.waste.annotation.EpiResponseFilters;
import net.zigin.nhi.could.waste.dto.NoticeMessageDto;
import net.zigin.nhi.could.waste.dto.SysRoleDto;
import net.zigin.nhi.could.waste.model.NoticeMessage;
import net.zigin.nhi.could.waste.service.NoticeMessageService;

import net.zigin.nhi.could.waste.service.SysRoleService;
import net.zigin.nhi.could.waste.util.HtmlUtils;
import net.zigin.nhi.could.waste.vo.JsonForResult;
import net.zigin.nhi.could.waste.vo.NoticeMessageVo;
import net.zigin.nhi.could.waste.vo.SysRoleVo;
import net.zigin.nhi.could.waste.vo.WasteBaseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * NoticeMessage控制器类
 *
 * @author mgw1986
 * @version V1.0
 * @ClassName: NoticeMessageController
 * @date 2021-9-14 15:44:48
 */
@Api(tags = "公告管理")
@RestController
@RequestMapping("/noticeMessage")
public class NoticeMessageController extends BaseController {
    @Autowired
    private NoticeMessageService noticeMessageService;
    @Autowired
    private SysRoleService sysRoleService;


    /**
     * 公告列表
     *
     * @param noticeMessageDto 公告信息
     * @return 公告列表
     */
    @ApiOperation("公告列表")
    @ApiImplicitParam(name = "noticeMessageDto", value = "公告信息", required = true, dataType = "NoticeMessageDto")
    @PostMapping("/getList")
    public JsonForResult<List<NoticeMessageVo>> getList(@RequestBody NoticeMessageDto noticeMessageDto) {
        List<NoticeMessageVo> list = noticeMessageService.getList(noticeMessageDto);
        Integer count = noticeMessageService.getCount(noticeMessageDto);
        return JsonForResult.<List<NoticeMessageVo>>builder()
                .data(list).total(count)
                .success(true).build();
    }

    @ApiOperation("当前用户公告列表")
    @GetMapping("/getCurrentUserList")
    public JsonForResult<List<NoticeMessageVo>> getCurrentUserList() {
        List<NoticeMessageVo> list = noticeMessageService.getCurrentUserList();
        return JsonForResult.<List<NoticeMessageVo>>builder()
                .data(list).total(list.size())
                .success(true).build();
    }

    /**
     * 公告详情
     *
     * @param id ID
     * @return 公告详情
     */
    @ApiOperation("公告详情")
    @ApiImplicitParam(name = "id", value = "公告id", required = true, dataType = "String")
    @GetMapping("/getById/{id}")
    public JsonForResult<NoticeMessageVo> getById(@PathVariable String id) {
        NoticeMessageVo noticeMessageVo = noticeMessageService.getInfoById(id);
        noticeMessageVo.setContent(HtmlUtils.delHtmlTag(noticeMessageVo.getContent()));
        return JsonForResult.<NoticeMessageVo>builder().data(noticeMessageVo).success(true).build();
    }

    @GetMapping("/read/{id}")
    @ApiOperation("阅读公告")
    @ApiImplicitParam(name = "id", value = "公告id", required = true, dataType = "String")
    public JsonForResult read(@PathVariable String id) {
        noticeMessageService.read(id);
        return JsonForResult.builder().success(true).build();
    }

    @ApiOperation("新增编辑公告")
    @ApiImplicitParam(name = "noticeMessageDto", value = "公告信息", required = true, dataType = "NoticeMessageDto")
    @PostMapping("/save")
    public JsonForResult<String> sava(@RequestBody NoticeMessageDto noticeMessageDto) {
        String id = noticeMessageService.saveOrUpdate(noticeMessageDto);
        return JsonForResult.<String>builder().data(id).success(true).build();
    }

    /**
     * 角色列表
     *
     * @return 角色列表
     */
    @GetMapping("/getRoleList")
    @ApiOperation("角色列表")
    public JsonForResult<List<SysRoleVo>> getList() {
        SysRoleDto roleDto = new SysRoleDto();
        roleDto.setDoublePlatformFlag("1");
        List<SysRoleVo> roleList = sysRoleService.getRoleList(roleDto);
        Integer count = sysRoleService.getRoleCount(roleDto);
        return JsonForResult.<List<SysRoleVo>>builder()
                .data(roleList).total(count)
                .success(true).build();
    }

}
